/************************************************************************
 * AIDE/Tools - Automata Identification Engine
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     
 * Description  :     
 * Change log   :     	-Date:  Change
 ************************************************************************/

using System;
using System.Reflection;
using SMLib.Automata.MM;

namespace TestingApp
{
	/// <summary>
	/// Load test model.
	/// </summary>
	public class LoadTestModel
	{
		Assembly asm;

		/// <summary>
		/// Initializes a new instance of the <see cref="TestingApp.LoadTestModel"/> class.
		/// </summary>
		/// <param name="path">Path.</param>
		public LoadTestModel (string path)
		{
			asm = Assembly.LoadFrom (path);						
			if (asm == null)
				throw new Exception ("The library is not there");		
		}

		/// <summary>
		/// Load the specified class
		/// </summary>
		/// <param name="cls">Name of the class</param>
		public object[] Load (string cls)
		{			
			Type t = asm.GetType (cls);
			if (t == null)
				throw new Exception ("The class is not there");
			
			MethodInfo m = t.GetMethod ("Construct", BindingFlags.Static | BindingFlags.Public);
			if (m == null)
				throw new Exception ("The create method is not there");
			
			object o = m.Invoke (null, null);

			return (object[])o;
		}
	}
}

